# -*- coding: utf-8 -*-
# @Time : 2021/9/18 9:17
# @Author : 伟哥
# @Email : xw@gmail.com
# @File : help_page.py
# @Project : mryx_test
'''客服与帮助页面的定位器与操作'''
from appium.webdriver.common.mobileby import MobileBy as By
from page.base_page import BasePage
from utils.util import send_keys
class Help(BasePage):
    '''客服与帮助'''
    online_locator = (By.ID, "cn.missfresh.application:id/service_btn_img_bg")
    delivery_locator = (By.XPATH, '//android.widget.TextView[@text=\"1.疫情地区配送问题\"]')
    delivery_response_locator = (By.XPATH, '//android.widget.TextView[@text=\"您好，疫情地区购买及配送情况，以您定位地址后的页面显示为准。若定位收货地址后页面可以正常下单，则说明您的地址可以正常配送\"]')
    enter_locator = (By.ID, 'cn.missfresh.application:id/sobot_et_sendmessage')
    violation_response_locator = (By.XPATH, '//android.widget.TextView[@text=\"您好，优优暂时回答不上来您的问题，还在努力学习中哦～输入“人工”，马上为您联系人工客服。\"]')

    def online(self):
        '''点击在线客户'''
        self.driver.find_element(*self.online_locator).click()

    def delivery(self):
        '''点击疫情配送问题'''
        self.driver.find_element(*self.delivery_locator).click()

    def delivery_response(self):
        '''获取疫情问题的回答'''
        dev = self.driver.find_element(*self.delivery_response_locator)
        return dev.text

    def enter(self,problem="蒂芬规划局"):
        '''客服输入框输入不正确问题'''
        send_keys(self.driver,self.enter_locator,problem)

    def violation_response(self):
        '''输入机器人不能回答的问题的答复'''
        violat = self.driver.find_element(*self.violation_response_locator)
        return violat.text
